package main

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

type Controller interface {
	// Prepare()
	// Finish()
	Handle(c *gin.Context)
}

func RegisterHandle(path string, ctrl Controller) {
	route.POST(path, func() gin.HandlerFunc {
		return func(c *gin.Context) {
			// ctrl.Prepare()
			ctrl.Handle(c)
			// ctrl.Finish()
		}
	}())
}

//////////////////////////////////////////////////////

type IndexRequest struct {
	Name string
	Age  int
}

type IndexControl struct{}

func (this *IndexControl) Handle(c *gin.Context) {
	r := &IndexRequest{}
	if err := c.BindJSON(r); err != nil {
		return
	}
	//time.Sleep(5 * time.Second)
	c.JSON(http.StatusOK, r)
}

//////////////////////////////////////////////////////

type GetUserControl struct{}

func (this *GetUserControl) Handle(c *gin.Context) {
	c.String(http.StatusOK, "OK")
}
